package testDemo;

import com.afishing.dao.ShopDao;
import com.afishing.dao.impl.ShopDaoImpl;
import com.afishing.entity.Shop;
import com.afishing.utils.JDBCUtil;
import org.junit.jupiter.api.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;

public class test1 {
    class Titles {
        private Integer empNo;
        private String title;
        private Date fromDate;
        private Date toDate;

        public Titles(Integer empNo, String title, Date fromDate, Date toDate) {
            this.empNo = empNo;
            this.title = title;
            this.fromDate = fromDate;
            this.toDate = toDate;
        }
    }
    @Test
    public void test1() {
        List<Titles> list = new ArrayList<>(1000);
        try {
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/employees", "root", "wsp0222.");
            PreparedStatement statement = connection.prepareStatement("select * from titles where title like ? limit 200");
           statement.setString(1, "%en%");
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                String num = resultSet.getString("emp_no");
                Integer empNo = Integer.parseInt(num);
                String birthDate = resultSet.getString("title");
                String fromDate1 = resultSet.getString("from_date");
                String toDate1 = resultSet.getString("to_date");
                Date firstDate = Date.valueOf(fromDate1);
                Date lastDate = Date.valueOf(toDate1);
                Titles titles = new Titles(empNo, birthDate, firstDate, lastDate);
                list.add(titles);
            }
            resultSet.close();
            statement.close();
            connection.close();
            for (Titles titles : list) {
                System.out.println(titles.empNo + " " + titles.title + " " + titles.fromDate + " " + titles.toDate);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
    @Test
    public void test2() {
        Properties properties = new Properties();
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("src/main/resources/db.properties");
            properties.load(fileInputStream);
            String driver = properties.getProperty("jdbc.driver");
            System.out.println(driver);

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    @Test
    public void test3(){
        ShopDao shopDao = new ShopDaoImpl();
        ArrayList<Shop> allShop = shopDao.getAllShop();
        allShop.forEach(System.out::println);
    }
}
